#pragma once
#include "KeyboardInput.hpp"
#include "Timer.hpp"
#include "Vector2D.h"
#include <string>
#include <vector>
using namespace std;

// Key concepts taken from lazyfoo.net

class Chatbox
{
private:
	struct LogMessage
	{
		LogMessage() {currentFadeLevel = 1.0;}
		string str;
		Timer tmr, INTERNAL_TIMER;
		float currentFadeLevel; // internal
	};

	int m_maxInputSize, m_maxLogSize, m_deleteTicks, m_textFadeTime, m_scrollCurrentPos;
	float m_textFadeSpeed;
	
	string m_font;
	bool m_active;
	
	Timer m_blinker;
	Timer m_BackspaceFilter;

	Coords m_location;
	Dimension m_dimensions;
	OGL_Color m_backgroundColor, m_fontColor;

	KeyboardInput m_inputDevice;
	vector<LogMessage> m_log;

public:
	Chatbox();
	
	void SetDeletionTime(int ticks)					{m_deleteTicks = ticks;}	// In milliseconds
	void SetFont(const string& name)				{m_font = name;}
	void SetLogSize(int size)						{m_maxLogSize = size; m_log.reserve(size);}
	void SetMaximumInputSize(int size)				{m_maxInputSize = size;}
	void SetLocation(const Coords& location)		{m_location = location;}
	void SetDimensions(const Dimension& dimensions)	{m_dimensions = dimensions;}
	void SetBackgroundColor(const OGL_Color& color) {m_backgroundColor = color;}
	void SetFontColor(const OGL_Color& color)		{m_fontColor = color;}

	bool IsActive()	{return m_active;}

	void HandleEvents(const SDL_Event& event, Uint8 *keystates);
	void HandleDeleteEvents(bool deleteItems);
	void AddMessage(char* message);
	void Render();
};
